package com.origin.netlibrary

import androidx.annotation.RestrictTo
import java.text.DecimalFormat

@RestrictTo(RestrictTo.Scope.LIBRARY)
object Utils {
    fun setSize(size: Long): String {
        //获取到的size为：1705230
        val GB = 1024 * 1024 * 1024//定义GB的计算常量
        val MB = 1024 * 1024//定义MB的计算常量
        val KB = 1024//定义KB的计算常量
        val df = DecimalFormat("0.00")//格式化小数
        return when {
            size / GB >= 1 -> //如果当前Byte的值大于等于1GB
                df.format((size / GB.toFloat()).toDouble()) + "GB   "
            size / MB >= 1 -> //如果当前Byte的值大于等于1MB
                df.format((size / MB.toFloat()).toDouble()) + "MB   "
            size / KB >= 1 -> //如果当前Byte的值大于等于1KB
                df.format((size / KB.toFloat()).toDouble()) + "KB   "
            else -> size.toString() + "B   "
        }
    }

}